require 'rexml/document'
require 'c:/tools/kronos/ruby/fsm'
require 'c:/tools/kronos/ruby/interface'
require 'c:/tools/kronos/ruby/createfiles'
require 'c:/tools/kronos/ruby/multiPageFSM'

file = File.new("../xml_demos/xmlPlayground.vdx")
xml_doc = REXML::Document.new file
file.close

interfaceView = nil
fsmView = Array.new

# seperate interface page from fsm descriptive pages
xml_doc.root.elements["Pages"].each { |element|
	if "Interface" == element.attributes["Name"]
		interfaceView = element
	elsif nil != element.attributes["Name"].index("FSM")
		fsmView.push(element.elements["Shapes"])
	else
		puts "Not Processing #{element.attributes["Name"]} Page"
	end
}

# Inteface Page Decoding
interface_page = Interface.new interfaceView.elements["Shapes"]

fsm_page = MultiPageFSM.new fsmView

# Finalize FSM Code
final_docs = FSMDocuments.new interface_page, fsm_page
final_docs.createTablesFile
final_docs.createStatesFiles
final_docs.createFSMFile
final_docs.createContextFiles

